import { Body, Controller, HttpCode, HttpStatus, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiCreatedResponse, ApiOperation } from '@nestjs/swagger';
import { AuthService } from 'src/modules/common/auth/auth.service';
import { LoginDto } from './dto/login.dto';

@Controller()
export class LoginController {
    constructor(
        private readonly authService: AuthService
    ){}
    @ApiOperation({
        summary: '用户登陆',
        description: '用户登陆',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @UseGuards(AuthGuard('local')) //使用local策略
    @Post('login')
    @HttpCode(HttpStatus.OK)
    async login(@Body() loginDto: LoginDto) {
        const result = await this.authService.login(loginDto)
        return result
    }
}
